﻿//-----------------------------------------------------------------------
// <copyright file="IToolManager.cs" company="Nathan Miller">
// Copyright (c) Nathan Miller.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
// 
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
//-----------------------------------------------------------------------
namespace TileTool.Tool
{
    using System;
    using System.Collections.Generic;
    using TileTool.Message;

    /// <summary>
    /// Interface for classes which manager tools inside of the editor.
    /// 
    /// The tool manger keep a stack of installed tools with the most recently
    /// installed tool placed on the top of the stack.
    /// </summary>
    public interface IToolManager
    {
        #region Events

        /// <summary>
        /// Event triggered before a tool has Install() called on it.
        /// </summary>
        event Action<ITool> Installed;

        /// <summary>
        /// Event triggered after a tool has Uninstall() called on it.
        /// </summary>
        event Action<ITool> Uninstalled;

        #endregion

        #region Properties

        /// <summary>
        /// Gets the message router messages should be sent on.
        /// </summary>
        MessageRouter MessageRouter
        {
            get;
        }

        #endregion

        #region Methods

        /// <summary>
        /// Test to see if the passed tool's type is in the tool stack.
        /// 
        /// Note, this does not test for the tool reference itself, but for the tool's type.
        /// </summary>
        /// <param name="tool">Tool type to look for in the tool stack.</param>
        /// <returns>Returns true if the tool type is contained in the tool stack.</returns>
        bool ContainsTool(ITool tool);

        /// <summary>
        /// Test to see if the passed tool type is in the tool stack.
        /// </summary>
        /// <param name="toolType">Tool type to look for in the stack.</param>
        /// <returns>Returns true if the tool type is contianed in the tool stack.</returns>
        bool ContainsTool(Type toolType);

        /// <summary>
        /// Install the passed tool into the tool stack.
        /// 
        /// On successful install of a tool, a IToolInstalledMessage message must be sent.
        /// 
        /// Only a single tool which returns ToolMode.Modal can exist in the stack at once.
        /// When a modal tool is installed, the other modal tool must be uninstalled.
        /// 
        /// Only a single type of tool can exist in the tool manager at a single time. If we have
        /// a tool named DefaultTool and it is installed twice, the second installed will fail
        /// since the type already exists in the tool manager.
        /// </summary>
        /// <param name="tool">Tool to isntall into the tool stack.</param>
        /// <returns>Returns true if the tool was installed or false if a tool of the passed
        /// type already exists in the stack.</returns>
        bool Install(ITool tool);

        /// <summary>
        /// Uninstall the passed tool type from the tool stack.
        /// 
        /// On successful uninstall of a tool, a IToolUninstalledMessage message must be sent.
        /// </summary>
        /// <param name="toolType">Tool type to uninstall from the tool stack.</param>
        void Uninstall(Type toolType);

        /// <summary>
        /// Uninstall the active modal tool if there is one.
        /// </summary>
        void UninstallModal();

        #endregion
    }
}
